﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlimDX;
using System.Deployment;
using System.Drawing;
using SlimDX.Direct3D9;
using System.Windows.Forms;


namespace GameStudio.Framework.GraphicsEngine
{
    public class DeviceContext
    {
        private DeviceContext()
        {
            Initilize();
        }

        private static DeviceContext _context = null;
        public static DeviceContext Current
        {
            get
            {
                if (_context == null)
                    _context = new DeviceContext();
                return _context;
            }
        }

        public Device Device { private set; get; }
        public Direct3D Adapter { private set; get; }
        public Form MainForm { private set; get; }

        public void Initilize()
        {
            Adapter = new Direct3D();
            MainForm = new Form();
            MainForm.Width = 500;
            MainForm.Height = 400;
            PresentParameters presentParameters = new PresentParameters();

            presentParameters.Windowed = true;
            presentParameters.BackBufferCount = 1;
            presentParameters.BackBufferFormat = Adapter.Adapters[0].CurrentDisplayMode.Format;
            presentParameters.BackBufferHeight = Adapter.Adapters[0].CurrentDisplayMode.Height;
            presentParameters.BackBufferWidth = Adapter.Adapters[0].CurrentDisplayMode.Width;
            presentParameters.SwapEffect = SwapEffect.Discard;

            Device = new Device(Adapter, 0, DeviceType.Hardware, MainForm.Handle,
                                       CreateFlags.HardwareVertexProcessing, presentParameters);

            //DeviceContext.Current.Device.SetRenderState(RenderState.FillMode, FillMode.Solid);
        }
    }
}
